import Mock from "mockjs";
import siteEntity from "../model/site.entity"


const siteInstance = new siteEntity();

// 基础获取设置
Mock.mock(
  RegExp("/mock/api/site/detail" + ".*"),
  "get",
  () => {
    return {
      code: 200,
      msg: "success",
      data: siteInstance.findAll(),
    };
  }
);

// 基础编辑设置
Mock.mock(
  RegExp("/mock/api/site/edit" + ".*"),
  "post",
  (request: any) => {
    let res = JSON.parse(request.body);
    let data:any = {};
    Object.entries(res).forEach((item:any[]) => {
      data[item[0]] = siteInstance.updateOne(item[0], item[1]);
    })
    return {
      code: 200,
      msg: "success",
      data,
    };
  }
);